home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / datescrn.arc / TIME.C < prev   
Encoding:
Text File  |  1985-12-12  |  2.5 KB  |  92 lines

  1. /*  time()  */
  2. /*  This function performs a system function call to get the system */
  3. /*  time, and returns a formattted string via the pointer `ptr'. */
  4.  
  5. time(ptr, mode)
  6. char *ptr;
  7. int  mode;
  8. #define GET_TIME  0x2C
  9. #define byte char
  10. #define ONE   1
  11. #define TWO   2
  12. #define THREE 3
  13. #define FOUR  4
  14. #define FIVE  5
  15. #define SIX   6
  16. #define SEVEN 7
  17.  
  18. {
  19.  
  20.      int hold_yr;
  21.      struct  XREG {short ax, bx, cx, dx, si, di;};
  22.      struct  HREG {byte  al, ah, bl, bh, cl, ch, dl, dh;};
  23.      union   REGS {
  24.                struct  XREG x;
  25.                struct  HREG h;
  26.      } inregs, outregs;
  27.  
  28.      struct  dt  {
  29.                short hour;
  30.                short minute;
  31.                short second;
  32.                short hundred;
  33.                char  *ampm;
  34.      };
  35.  
  36.      
  37.      static char *name[] = {
  38.           "AM", "PM"
  39.      };
  40.  
  41.      struct dt pdate;
  42.      
  43.      inregs.h.ah = GET_TIME;
  44.      inregs.h.al = 0;
  45.      intdos(&inregs, &outregs);
  46.      
  47.      pdate.hour  = outregs.h.ch;
  48.      pdate.minute = outregs.h.cl;
  49.      pdate.second = outregs.h.dh;
  50.      pdate.hundred= outregs.h.dl;
  51.  
  52.      if (pdate.hour >= 12)  {
  53.           pdate.hour -= 12;
  54.           pdate.ampm = name[1];       
  55.           if (pdate.hour < 1)
  56.                pdate.hour = 12;
  57.      } else {
  58.           pdate.ampm = name[0];        
  59.           if (pdate.hour < 1)
  60.                pdate.hour = 12;
  61.      }
  62.     
  63.      switch (mode) {
  64.      case ONE:
  65.           sprintf(ptr, "%02d%02d%02d",pdate.hour,pdate.minute,pdate.second);
  66.           break;
  67.      case TWO:
  68.           sprintf(ptr,"%02d:%02d:%02d",pdate.hour,pdate.minute,pdate.second);
  69.           break;
  70.      case THREE:
  71.           sprintf(ptr, "%02d%02d%02d%02d", pdate.hour, pdate.minute,
  72.                                            pdate.second, pdate.hundred);  
  73.           break;
  74.      case FOUR:
  75.           sprintf(ptr, "%02d:%02d:%02d.%02d", pdate.hour, pdate.minute,
  76.                                            pdate.second, pdate.hundred);  
  77.           break;
  78.      case FIVE:
  79.           sprintf(ptr, "%02d:%02d", pdate.hour, pdate.minute);
  80.           break;
  81.      case SIX:
  82.           sprintf(ptr, "%02d:%02d:%02d %s", pdate.hour, pdate.minute,
  83.                                            pdate.second, pdate.ampm);  
  84.           break;
  85.      case SEVEN:
  86.           sprintf(ptr, "%02d:%02d %s", pdate.hour, pdate.minute, pdate.ampm);
  87.           break;
  88.      default:
  89.           break;
  90.      }   
  91. }
  92.